package br.com.reparoja.persistence;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.google.appengine.api.utils.SystemProperty;

public final class Factory {

	//private static final EntityManagerFactory emfInstance = Persistence.createEntityManagerFactory("reparoja-persistence");
	
	private static final EntityManagerFactory emfInstance;

	static {
	    Map<String, String> properties = new HashMap<String, String>();
	    
		if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
			properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.GoogleDriver");
			properties.put("javax.persistence.jdbc.url", "jdbc:google:mysql://reparoja-br:reparoja-mysql/reparojadb?user=root");
			properties.put("javax.persistence.jdbc.user", "root");

			//properties.put("javax.persistence.jdbc.url", System.getProperty("cloudsql.url"));
		}
		else {
			properties.put("javax.persistence.jdbc.driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
			//properties.put("javax.persistence.jdbc.url", System.getProperty("cloudsql.url.dev"));
			properties.put("javax.persistence.jdbc.url", "jdbc:sqlserver://localhost:1433;databaseName=REPAROJA2");
			properties.put("javax.persistence.jdbc.user", "sa");
			properties.put("javax.persistence.jdbc.password", "123456");
			
			
			properties.put("hibernate.show_sql", "true");
			properties.put("hibernate.format_sql", "true");
		}
		
		emfInstance = Persistence.createEntityManagerFactory("reparoja", properties);
	}

	private Factory() {

	}

	public static EntityManagerFactory get() {
		return emfInstance;
	}
}